<!DOCTYPE html>
<html>
<head>
  <title>WebSocket Client B</title>
  <script>
    const clientId = 'CCCCC'; // 客户端 ID
    const ws = new WebSocket(`ws://localhost:3000/?clientId=${clientId}`);

    ws.onopen = function() {
      console.log('客户端 C 已连接到 WebSocket 服务器');
    };

    ws.onmessage = function(event) {
      console.log('客户端 C 收到消息:', event.data);
      document.getElementById('h2').innerHTML = event.data;
    };

    ws.onclose = function() {
      console.log('客户端 C 关闭连接');
    };

    function sendMessage() {
      const message = document.getElementById('message-input').value;

      let obj ={
        clientId: clientId,
        message: document.getElementById('message-input').value
      }
      ws.send( JSON.stringify(obj));
    }
  </script>
</head>
<body>
  <h1>WebSocket Client C</h1>
  <input type="text" id="message-input" placeholder="输入消息">
  <button onclick="sendMessage()">发送消息</button>
  <h2 id="h2"></h2>
</body>
</html>